<?php
	class Default_Model_DbTable_Sample extends Zend_Db_Table_Abstract
	{
	    protected $_name = 'TABLE_NAME';
	    protected $_sequence = '_seq_TABLE_NAME';

	    protected $_primary = 'id';
	    protected $_pk = 'id';


	    public function getRow($id, $returnArray = false)
	    {
	        $id = (int)$id;
	    	$row = $this->fetchRow($this->_pk .'= '. $id);
	        if (!$row) {
	            throw new Exception("Count not find row $id");
	        }
	        if ($returnArray == true) {
		        return $row->toArray();
	        }
	        return $row;

	    }

	    public function getRows($filterArr = array(), $orderArr = array())
	    {

	        $filter = $this->select();
	        if (!empty($filterArr)) {
		        foreach ($filterArr as $field_id=>$field_value) {
			    	$filter->where($field_id . ' = ?', $field_value);
		        }
	        }
	        if (!empty($orderArr)) {
		        foreach ($orderArr as $field_id=>$orderType) {
			    	$filter->order($field_id .' '. $orderType);
		        }//echo $filter;exit;
	        }

	    	$rowsTemp = $this->fetchAll($filter);
	        if (!$rowsTemp) {
	            throw new Exception("Could not find rows");
	        }
	        $rowsTemp = $rowsTemp->toArray();

	        $pKey = $this->_pk;
	        foreach ($rowsTemp as $key=>$row) {
	        	$row = (object)$row;
	        	$rows[$row->$pKey] = $row;
	        }
	        return $rows;
	        //return $rows;

	    }

	    public function getRowsAsPairs($key='id', $label='label', $filterArr = array(), $orderArr = array())
	    {
	    	$filter = $this->select()->from($this->_name, array($key, $label));

	    	if (!empty($filterArr)) {
		        foreach ($filterArr as $field_id=>$field_value) {
			    	$filter->where($field_id . ' = ?', $field_value);
		        }
	        }
	        if (!empty($orderArr)) {
		        foreach ($orderArr as $field_id=>$orderType) {
			    	$filter->order($field_id .' '. $orderType);
		        }//echo $filter;exit;
	        }

	    	$rows = $this->_db->fetchPairs($filter);
	        if (!$rows) {
	            throw new Exception("Count not find rows");
	        }
	        return $rows;

	    }

	    public function addRow($data)
	    {

	        $this->insert($data);
	        $id = $this->_db->lastInsertId($this->_name);
	        return $id;
	    }

	    public function updateFUNC($id, $data)
	    {
	        $this->update($data, $this->_pk . ' = ' . (int)$id);

	    }

	    public function deleteRow($id)
	    {
	        $this->delete($this->_pk .'=' . (int)$id);
	    }

	}